package com.tiger.life;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.CompoundButton.OnCheckedChangeListener;

public class CheckActivity extends BaseActivity {
	private Bundle bundle;
	private Intent intent;
	private int checkFlag;
	// 公共表单

	// 烟
	private EditText start_year, start_month, end_year, end_month, perdaynum;
	private ImageButton cigar_result, cigar_recheck;
	// 宝宝测试
	private int numA, numB, numC, numD;
	private RadioButton bb_subject_1, bb_subject_2, bb_subject_3, bb_subject_4;
	// 体重测试
	private float[] points = new float[19];
	private float totalPoint = 0, checkedPotin = 0;
	private int subjectNum = 1;
	private RadioGroup subjectrP;
	private TextView subject_tile;
	private RadioButton subject_1, subject_2, subject_3;
	private ImageButton weight_nextQbtn;
	// 卡路里
	private Spinner milltype, sex;
	private Button checkMill,result;
	private TextView checkedShiwu;
	private List<String[]> datas;
	private ListView dataView;
	private AlertDialog.Builder dia;
	private String[] topMills;
	private String milltype_txt,sex_txt;
	private float resultRieNum;//结果
	private float bzRieNum;//标准
	private float sumRieNum;//总共卡量
	private List<String> selectedNames=new ArrayList<String>();
	private CalorieAdapter caAdapter;
	// 魔法衣柜,//cigar_result
	private String colorSel;
	// 星座情缘（略）
	// 生活达人
	private TextView wentiGuli,eredar_q, eredar_a;
	/**
	 * subject_1,subject_2,subject_3; subjectrP
	 */
	// 谣言粉碎机（略）
	// 狗狗聪明测试
	private float[] dogpoints = new float[12];

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.index);

		
		bundle = this.getIntent().getExtras();
		checkFlag = bundle.getInt(CommonUtil.checkFlag);
		intent = new Intent(this, ResultActivity.class);
		if (checkFlag == CommonUtil.checkFlagValue.cigar_Flag) {
			setContentView(R.layout.cigar_check);
		} else if (checkFlag == CommonUtil.checkFlagValue.baby_Flag) {
			setContentView(R.layout.baby_check);
		} else if (checkFlag == CommonUtil.checkFlagValue.weight_Flag) {
			setContentView(R.layout.weight_check);
		} else if (checkFlag == CommonUtil.checkFlagValue.calorie_Flag) {
			setContentView(R.layout.calorie_check);
		} else if (checkFlag == CommonUtil.checkFlagValue.chest_Flag) {
			setContentView(R.layout.chest_check);
		} else if (checkFlag == CommonUtil.checkFlagValue.xingzuo_Flag) {

		} else if (checkFlag == CommonUtil.checkFlagValue.eredar_Flag) {
			setContentView(R.layout.eredar_check);
		} else if (checkFlag == CommonUtil.checkFlagValue.rumor_Flag) {

		} else {
			setContentView(R.layout.dog_check);
		}

		initView();
		initAction();
	}

	public void initView() {
		if (checkFlag == CommonUtil.checkFlagValue.cigar_Flag) {
			start_year = (EditText) this.findViewById(R.id.start_year);
			start_month = (EditText) this.findViewById(R.id.start_month);
			end_year = (EditText) this.findViewById(R.id.end_year);
			end_month = (EditText) this.findViewById(R.id.end_month);
			perdaynum = (EditText) this.findViewById(R.id.perdaynum);
			cigar_result = (ImageButton) this.findViewById(R.id.result);
			cigar_recheck = (ImageButton) this.findViewById(R.id.recheck);
		} else if (checkFlag == CommonUtil.checkFlagValue.baby_Flag) {
			weight_nextQbtn = (ImageButton) this.findViewById(R.id.nextQbtn);
			subject_tile = (TextView) this.findViewById(R.id.q_title);
			bb_subject_1 = (RadioButton) this.findViewById(R.id.subject_1);
			bb_subject_2 = (RadioButton) this.findViewById(R.id.subject_2);
			bb_subject_3 = (RadioButton) this.findViewById(R.id.subject_3);
			bb_subject_4 = (RadioButton) this.findViewById(R.id.subject_4);
			subjectrP = (RadioGroup) this.findViewById(R.id.radioGroup);
		} else if (checkFlag == CommonUtil.checkFlagValue.weight_Flag) {
			weight_nextQbtn = (ImageButton) this.findViewById(R.id.nextQbtn);
			subject_tile = (TextView) this.findViewById(R.id.q_title);
			subject_1 = (RadioButton) this.findViewById(R.id.subject_1);
			subject_2 = (RadioButton) this.findViewById(R.id.subject_2);
			subject_3 = (RadioButton) this.findViewById(R.id.subject_3);
			subjectrP = (RadioGroup) this.findViewById(R.id.radioGroup);
		} else if (checkFlag == CommonUtil.checkFlagValue.calorie_Flag) {
			milltype=(Spinner)this.findViewById(R.id.spinner_milltype);
			sex=(Spinner)this.findViewById(R.id.spinner_sex);
			checkMill=(Button)this.findViewById(R.id.checkMill);
			result=(Button)this.findViewById(R.id.result);
			checkedShiwu=(TextView)this.findViewById(R.id.checkedShiwu);
			checkedShiwu.setText("未选择食物");
			dataView=new ListView(this);
			topMills=CheckActivity.this.getResources().getStringArray(R.array.topMill);
		} else if (checkFlag == CommonUtil.checkFlagValue.chest_Flag) {
			cigar_result = (ImageButton) this.findViewById(R.id.result);
			bb_subject_1 = (RadioButton) this.findViewById(R.id.subject_1);
			bb_subject_2 = (RadioButton) this.findViewById(R.id.subject_2);
			bb_subject_3 = (RadioButton) this.findViewById(R.id.subject_3);
			bb_subject_4 = (RadioButton) this.findViewById(R.id.subject_4);
			subjectrP = (RadioGroup) this.findViewById(R.id.radioGroup);
		} else if (checkFlag == CommonUtil.checkFlagValue.xingzuo_Flag) {

		} else if (checkFlag == CommonUtil.checkFlagValue.eredar_Flag) {
			subjectrP = (RadioGroup) this.findViewById(R.id.radioGroup);
			eredar_q = (TextView) this.findViewById(R.id.eredar_q);
			wentiGuli=(TextView)this.findViewById(R.id.wentiGuli);
			eredar_a = (TextView) this.findViewById(R.id.eredar_a);
			subject_1 = (RadioButton) this.findViewById(R.id.subject_1);
			subject_2 = (RadioButton) this.findViewById(R.id.subject_2);
			subject_3 = (RadioButton) this.findViewById(R.id.subject_3);
		} else if (checkFlag == CommonUtil.checkFlagValue.rumor_Flag) {

		} else {
			weight_nextQbtn = (ImageButton) this.findViewById(R.id.nextQbtn);
			subject_tile = (TextView) this.findViewById(R.id.q_title);
			bb_subject_1 = (RadioButton) this.findViewById(R.id.subject_1);
			bb_subject_2 = (RadioButton) this.findViewById(R.id.subject_2);
			bb_subject_3 = (RadioButton) this.findViewById(R.id.subject_3);
			bb_subject_4 = (RadioButton) this.findViewById(R.id.subject_4);
			subjectrP = (RadioGroup) this.findViewById(R.id.radioGroup);
		}
	}

	public void initAction() {
		if (checkFlag == CommonUtil.checkFlagValue.cigar_Flag) {
			cigar_result.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View arg0) {
					// TODO Auto-generated method stub
					int age_years = 0;
					int age_days = 0;
					int bad_days = 0;
					int bad_hours = 0;
					String start_year_txt = start_year.getText().toString();
					String start_month_txt = start_month.getText().toString();
					String end_year_txt = end_year.getText().toString();
					String end_month_txt = end_month.getText().toString();
					String perdaynum_txt = perdaynum.getText().toString();
					if (Integer.parseInt(start_month_txt) < 10
							&& !start_month_txt.startsWith("0")) {
						start_month_txt = "0" + start_month_txt;
					}
					if (Integer.parseInt(end_month_txt) < 10
							&& !end_month_txt.startsWith("0")) {
						end_month_txt = "0" + end_month_txt;
					}
					int days = 0;
					try {
						days = CommonUtil.getDay(start_year_txt + "-"
								+ start_month_txt, end_year_txt + "-"
								+ end_month_txt);
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						Toast.makeText(CheckActivity.this, "日期格式错误",
								Toast.LENGTH_LONG).show();
					}
					age_years = (int) (days / 365);
					age_days = days - age_years * 365;
					int minutes = days * Integer.parseInt(perdaynum_txt) / 10;
					bad_days = (int) (minutes / 60 / 24);
					bad_hours = (int) (minutes / 60) - bad_days * 24;
					bundle.putInt(CommonUtil.age_years, age_years);
					bundle.putInt(CommonUtil.age_days, age_days);
					bundle.putInt(CommonUtil.bad_days, bad_days);
					bundle.putInt(CommonUtil.bad_hours, bad_hours);
					intent.putExtras(bundle);
					CheckActivity.this.startActivity(intent);
				}
			});
			cigar_recheck.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View arg0) {
					// TODO Auto-generated method stub
					CheckActivity.this.finish();
				}
			});
		} else if (checkFlag == CommonUtil.checkFlagValue.baby_Flag) {
			setBabyRadioText();
			bb_subject_1.setOnCheckedChangeListener(babyListener);
			bb_subject_2.setOnCheckedChangeListener(babyListener);
			bb_subject_3.setOnCheckedChangeListener(babyListener);
			bb_subject_4.setOnCheckedChangeListener(babyListener);
			weight_nextQbtn.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View arg0) {
					if (!validFourChecked()) {
						Toast.makeText(CheckActivity.this, "请选择相应选项",
								Toast.LENGTH_LONG).show();
						return;
					}
					// TODO Auto-generated method stub
					if (subjectNum == 10) {
						bundle.putString(CommonUtil.babyResult, CommonUtil
								.getMostNum(numA, numB, numC, numD));
						intent.putExtras(bundle);
						CheckActivity.this.startActivity(intent);
						return;
					}
					subjectNum++;
					setBabyRadioText();
				}

			});
		} else if (checkFlag == CommonUtil.checkFlagValue.weight_Flag) {
			setWeightRadioText();
			subject_1.setOnCheckedChangeListener(weightListener);
			subject_2.setOnCheckedChangeListener(weightListener);
			subject_3.setOnCheckedChangeListener(weightListener);

			weight_nextQbtn.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View arg0) {
					if (!validThreeChecked()) {
						Toast.makeText(CheckActivity.this, "请选择相应选项",
								Toast.LENGTH_LONG).show();
						return;
					}
					// TODO Auto-generated method stub
					if (subjectNum == 19) {
						for (float point : points) {
							totalPoint += point;
						}
						bundle.putFloat(CommonUtil.weightResult, totalPoint);
						intent.putExtras(bundle);
						CheckActivity.this.startActivity(intent);
						return;
					}
					subjectNum++;
					setWeightRadioText();
				}

			});
		} else if (checkFlag == CommonUtil.checkFlagValue.calorie_Flag) {
			ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
					this, R.array.shiwutype,
					android.R.layout.simple_spinner_item);
			adapter
					.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
			milltype.setAdapter(adapter);
			milltype.setOnItemSelectedListener(new OnItemSelectedListener() {
				public void onItemSelected(AdapterView<?> parent, View view,
						int position, long id) {
					 if(position==0){
						 milltype_txt=CommonUtil.calorieInter.zao;
					 }else if(position==1){
						 milltype_txt=CommonUtil.calorieInter.wu;
					 }else{
						 milltype_txt=CommonUtil.calorieInter.wan;
					 }
				}

				public void onNothingSelected(AdapterView<?> parent) {

				}
			});
			ArrayAdapter<CharSequence> sexadapter = ArrayAdapter.createFromResource(
					this, R.array.sex,
					android.R.layout.simple_spinner_item);
			sexadapter
					.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
			sex.setAdapter(sexadapter);
			sex.setOnItemSelectedListener(new OnItemSelectedListener() {
				public void onItemSelected(AdapterView<?> parent, View view,
						int position, long id) {
					if(position==0){
						 sex_txt=CommonUtil.calorieInter.man;
					 }else{
						 sex_txt=CommonUtil.calorieInter.wuman;
					 }
				}
				public void onNothingSelected(AdapterView<?> parent) {

				}
			});
			checkMill.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View arg0) {
					if(selectedNames==null){
						selectedNames=new ArrayList<String>();
					}
					// TODO Auto-generated method stub
					if(dia!=null){
						dia=null;
					}
					dia=new AlertDialog.Builder(CheckActivity.this);
					dia.setTitle("选择类别").setItems(topMills, new android.content.DialogInterface.OnClickListener(){

						@Override
						public void onClick(DialogInterface dialog, int which) {
							dialog.dismiss();
							// TODO Auto-generated method stub
//							Toast.makeText(CheckActivity.this,topMills[which] , Toast.LENGTH_LONG).show();
							showShiwuDialog(which);
						}
						
					}
					).setPositiveButton("取消", null).show();
				}
				
			});
			result.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View arg0) {
					if(sumRieNum==0){
						Toast.makeText(CheckActivity.this, "请先选择用餐食物", Toast.LENGTH_LONG).show();
						return;
					}
					String bzRieNumTxt="0";
					// TODO Auto-generated method stub
					if(milltype_txt.equals(CommonUtil.calorieInter.zao)){
						if(sex_txt.equals(CommonUtil.calorieInter.man)){
							bzRieNumTxt=CheckActivity.this.getString(R.string.zao_man);
						}else{
							bzRieNumTxt=CheckActivity.this.getString(R.string.zao_wuman);
						}
					}
					if(milltype_txt.equals(CommonUtil.calorieInter.wu)){
						if(sex_txt.equals(CommonUtil.calorieInter.man)){
							bzRieNumTxt=CheckActivity.this.getString(R.string.wu_man);
						}else{
							bzRieNumTxt=CheckActivity.this.getString(R.string.wu_wuman);
						}
					}
					if(milltype_txt.equals(CommonUtil.calorieInter.wan)){
						if(sex_txt.equals(CommonUtil.calorieInter.man)){
							bzRieNumTxt=CheckActivity.this.getString(R.string.wan_man);
						}else{
							bzRieNumTxt=CheckActivity.this.getString(R.string.wan_wuman);
						}
					}
					bzRieNum=Float.parseFloat(bzRieNumTxt);
//					Log.i("out", "sumRieNum:"+sumRieNum);
//					Log.i("out", "bzRieNum:"+bzRieNum);
					resultRieNum=sumRieNum-bzRieNum;
					bundle.putFloat(CommonUtil.calorieInter.result, resultRieNum);
					bundle.putFloat(CommonUtil.calorieInter.biaozhun, bzRieNum);
					bundle.putFloat(CommonUtil.calorieInter.zongsheru, sumRieNum);
					intent.putExtras(bundle);
					CheckActivity.this.startActivity(intent);
					return;
				}
				
			});
			caAdapter=new CalorieAdapter(this);
			dataView.setAdapter(caAdapter);
			dataView.setOnItemClickListener(new OnItemClickListener(){

				@Override
				public void onItemClick(AdapterView<?> arg0, View item,
						int position, long itemId) {
					// TODO Auto-generated method stub
					ApkHolder info=(ApkHolder)item.getTag();
					if (info != null) {
//						sumRieNum
						if (info.millSelect.isChecked()) {
							info.millSelect.setChecked(false);
							sumRieNum=sumRieNum-Float.parseFloat(info.rieNum);
							selectedNames.remove(info.typeName.getText().toString());
						} else {
							info.millSelect.setChecked(true);
							sumRieNum=sumRieNum+Float.parseFloat(info.rieNum);
							selectedNames.add(info.typeName.getText().toString());
						}
					}
				}
				
			});
		} else if (checkFlag == CommonUtil.checkFlagValue.chest_Flag) {
			cigar_result.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					if (!validFourChecked()) {
						Toast.makeText(CheckActivity.this, "请选择肤色",
								Toast.LENGTH_LONG).show();
						return;
					}
					// TODO Auto-generated method stub
					bundle.putString(CommonUtil.chestInter.colorSel, colorSel);
					intent.putExtras(bundle);
					CheckActivity.this.startActivity(intent);
					return;
				}
			});
			bb_subject_1.setOnCheckedChangeListener(chestListener);
			bb_subject_2.setOnCheckedChangeListener(chestListener);
			bb_subject_3.setOnCheckedChangeListener(chestListener);
			bb_subject_4.setOnCheckedChangeListener(chestListener);
		} else if (checkFlag == CommonUtil.checkFlagValue.xingzuo_Flag) {

		} else if (checkFlag == CommonUtil.checkFlagValue.eredar_Flag) {
			setEredarText();
			subject_1.setOnCheckedChangeListener(eredarListener);
			subject_2.setOnCheckedChangeListener(eredarListener);
			subject_3.setOnCheckedChangeListener(eredarListener);
		} else if (checkFlag == CommonUtil.checkFlagValue.rumor_Flag) {

		} else {
			setDogRadioText();
			bb_subject_1.setOnCheckedChangeListener(dogListener);
			bb_subject_2.setOnCheckedChangeListener(dogListener);
			bb_subject_3.setOnCheckedChangeListener(dogListener);
			bb_subject_4.setOnCheckedChangeListener(dogListener);

			weight_nextQbtn.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View arg0) {
					if (!validFourChecked()) {
						Toast.makeText(CheckActivity.this, "请选择相应选项",
								Toast.LENGTH_LONG).show();
						return;
					}
					// TODO Auto-generated method stub
					if (subjectNum == 12) {
						for (float point : dogpoints) {
							totalPoint += point;
						}
						bundle.putFloat(CommonUtil.dogResult, totalPoint);
						intent.putExtras(bundle);
						Log.i("out", "intent:"+intent);
						CheckActivity.this.startActivity(intent);
						return;
					}
					subjectNum++;
					setDogRadioText();
				}

			});
		}
	}

	OnCheckedChangeListener eredarListener = new OnCheckedChangeListener() {
		@Override
		public void onCheckedChanged(CompoundButton radio, boolean arg1) {
			// TODO Auto-generated method stub
			switch (radio.getId()) {
			case R.id.subject_1:
				eredar_a.setVisibility(View.VISIBLE);
				eredar_q.setVisibility(View.GONE);
				wentiGuli.setVisibility(View.VISIBLE);
				subject_1.setVisibility(View.GONE);
				subject_2.setVisibility(View.GONE);
				break;
			case R.id.subject_2:
				eredar_a.setVisibility(View.VISIBLE);
				eredar_q.setVisibility(View.GONE);
				wentiGuli.setVisibility(View.VISIBLE);
				subject_1.setVisibility(View.GONE);
				subject_2.setVisibility(View.GONE);
				break;
			case R.id.subject_3:
				if(subject_1.getVisibility()==View.VISIBLE&&
						subject_1.getVisibility()==View.VISIBLE){
				if(!subject_1.isChecked()&&!subject_2.isChecked()){
					Toast.makeText(CheckActivity.this, "请选择是或者否",
							Toast.LENGTH_LONG).show();
					return;
				}}
				if (subjectNum == 30) {
					intent.putExtras(bundle);
					CheckActivity.this.startActivity(intent);
					return;
				}
				subjectNum++;
				setEredarText();
				break;
			}
		}

	};
	OnCheckedChangeListener chestListener = new OnCheckedChangeListener() {
		@Override
		public void onCheckedChanged(CompoundButton radio, boolean arg1) {
			// TODO Auto-generated method stub
			switch (radio.getId()) {
			case R.id.subject_1:
				if (radio.isChecked()) {
					colorSel = CommonUtil.chestInter.color_yellow;
				}
				break;
			case R.id.subject_2:
				if (radio.isChecked()) {
					colorSel = CommonUtil.chestInter.color_black;
				}
				break;
			case R.id.subject_3:
				if (radio.isChecked()) {
					colorSel = CommonUtil.chestInter.color_white;
				}
				break;
			case R.id.subject_4:
				if (radio.isChecked()) {
					colorSel = CommonUtil.chestInter.color_red;
				}
				break;
			}
		}

	};
	OnCheckedChangeListener babyListener = new OnCheckedChangeListener() {
		@Override
		public void onCheckedChanged(CompoundButton radio, boolean arg1) {
			// TODO Auto-generated method stub
			switch (radio.getId()) {
			case R.id.subject_1:
				if (radio.isChecked()) {
					numA++;
				}
				break;
			case R.id.subject_2:
				if (radio.isChecked()) {
					numB++;
				}
				break;
			case R.id.subject_3:
				if (radio.isChecked()) {
					numC++;
				}
				break;
			case R.id.subject_4:
				if (radio.isChecked()) {
					numD++;
				}
				break;
			}
		}

	};
	OnCheckedChangeListener dogListener = new OnCheckedChangeListener() {
		@Override
		public void onCheckedChanged(CompoundButton radio, boolean arg1) {
			checkedPotin = 0;
			// TODO Auto-generated method stub
			switch (radio.getId()) {
			case R.id.subject_1:
				if (radio.isChecked()) {
					checkedPotin = Float
							.parseFloat(CheckActivity.this
									.getResources()
									.getString(
											CheckActivity.this
													.getResources()
													.getIdentifier(
															"com.tiger.life:string/dog_subject_value_"
																	+ subjectNum
																	+ "_1",
															null, null)));
				}
				break;
			case R.id.subject_2:
				if (radio.isChecked()) {
					checkedPotin = Float
							.parseFloat(CheckActivity.this
									.getResources()
									.getString(
											CheckActivity.this
													.getResources()
													.getIdentifier(
															"com.tiger.life:string/dog_subject_value_"
																	+ subjectNum
																	+ "_2",
															null, null)));
				}
				break;
			case R.id.subject_3:
				if (radio.isChecked()) {
					checkedPotin = Float
							.parseFloat(CheckActivity.this
									.getResources()
									.getString(
											CheckActivity.this
													.getResources()
													.getIdentifier(
															"com.tiger.life:string/dog_subject_value_"
																	+ subjectNum
																	+ "_3",
															null, null)));
				}
				break;
			case R.id.subject_4:
				if (radio.isChecked()) {
					checkedPotin = Float
							.parseFloat(CheckActivity.this
									.getResources()
									.getString(
											CheckActivity.this
													.getResources()
													.getIdentifier(
															"com.tiger.life:string/dog_subject_value_"
																	+ subjectNum
																	+ "_4",
															null, null)));
				}
				break;
			}
			dogpoints[subjectNum - 1] = checkedPotin;
		}

	};
	OnCheckedChangeListener weightListener = new OnCheckedChangeListener() {
		@Override
		public void onCheckedChanged(CompoundButton radio, boolean arg1) {
			checkedPotin = 0;
			// TODO Auto-generated method stub
			switch (radio.getId()) {
			case R.id.subject_1:
				if (radio.isChecked()) {
					checkedPotin = Float
							.parseFloat(CheckActivity.this
									.getResources()
									.getString(
											CheckActivity.this
													.getResources()
													.getIdentifier(
															"com.tiger.life:string/subject_value_"
																	+ subjectNum
																	+ "_1",
															null, null)));
				}
				break;
			case R.id.subject_2:
				if (radio.isChecked()) {
					checkedPotin = Float
							.parseFloat(CheckActivity.this
									.getResources()
									.getString(
											CheckActivity.this
													.getResources()
													.getIdentifier(
															"com.tiger.life:string/subject_value_"
																	+ subjectNum
																	+ "_2",
															null, null)));
				}
				break;
			case R.id.subject_3:
				if (radio.isChecked()) {
					checkedPotin = Float
							.parseFloat(CheckActivity.this
									.getResources()
									.getString(
											CheckActivity.this
													.getResources()
													.getIdentifier(
															"com.tiger.life:string/subject_value_"
																	+ subjectNum
																	+ "_3",
															null, null)));
				}
				break;
			}
			points[subjectNum - 1] = checkedPotin;
		}

	};

	private void setBabyRadioText() {
		subjectrP.clearCheck();
		bb_subject_1.setChecked(false);
		bb_subject_2.setChecked(false);
		bb_subject_3.setChecked(false);
		bb_subject_4.setChecked(false);
		subject_tile.setText(this.getResources().getIdentifier(
				"com.tiger.life:string/baby_subject_title_" + subjectNum, null,
				null));
		bb_subject_1.setText(this.getResources().getIdentifier(
				"com.tiger.life:string/baby_subject_" + subjectNum + "_1",
				null, null));
		bb_subject_2.setText(this.getResources().getIdentifier(
				"com.tiger.life:string/baby_subject_" + subjectNum + "_2",
				null, null));
		bb_subject_3.setText(this.getResources().getIdentifier(
				"com.tiger.life:string/baby_subject_" + subjectNum + "_3",
				null, null));
		bb_subject_4.setText(this.getResources().getIdentifier(
				"com.tiger.life:string/baby_subject_" + subjectNum + "_4",
				null, null));
	}

	private void setWeightRadioText() {
		subjectrP.clearCheck();
		subject_1.setChecked(false);
		subject_2.setChecked(false);
		subject_3.setChecked(false);
		subject_tile.setText(this.getResources()
				.getIdentifier(
						"com.tiger.life:string/subject_title_" + subjectNum,
						null, null));
		subject_1.setText(this.getResources().getIdentifier(
				"com.tiger.life:string/subject_" + subjectNum + "_1", null,
				null));
		subject_2.setText(this.getResources().getIdentifier(
				"com.tiger.life:string/subject_" + subjectNum + "_2", null,
				null));
		subject_3.setText(this.getResources().getIdentifier(
				"com.tiger.life:string/subject_" + subjectNum + "_3", null,
				null));
	}

	private void setDogRadioText() {
		subjectrP.clearCheck();
		bb_subject_1.setChecked(false);
		bb_subject_2.setChecked(false);
		bb_subject_3.setChecked(false);
		bb_subject_4.setChecked(false);
		subject_tile.setText(this.getResources().getIdentifier(
				"com.tiger.life:string/dog_subject_title_" + subjectNum, null,
				null));
		bb_subject_1.setText(this.getResources().getIdentifier(
				"com.tiger.life:string/dog_subject_" + subjectNum + "_1", null,
				null));
		bb_subject_2.setText(this.getResources().getIdentifier(
				"com.tiger.life:string/dog_subject_" + subjectNum + "_2", null,
				null));
		bb_subject_3.setText(this.getResources().getIdentifier(
				"com.tiger.life:string/dog_subject_" + subjectNum + "_3", null,
				null));
		bb_subject_4.setText(this.getResources().getIdentifier(
				"com.tiger.life:string/dog_subject_" + subjectNum + "_4", null,
				null));
	}

	private void setEredarText() {
		subjectrP.clearCheck();
		wentiGuli.setVisibility(View.GONE);
		eredar_q.setVisibility(View.VISIBLE);
		subject_1.setVisibility(View.VISIBLE);
		subject_2.setVisibility(View.VISIBLE);
		eredar_a.setVisibility(View.GONE);
		subject_1.setChecked(false);
		subject_2.setChecked(false);
		subject_3.setChecked(false);
		eredar_q.setText(this.getResources().getIdentifier(
				"com.tiger.life:string/eredar_subject_title_" + subjectNum,
				null, null));
		eredar_a.setText(this.getResources().getIdentifier(
				"com.tiger.life:string/eredar_subject_answer_" + subjectNum,
				null, null));
		switch(subjectNum){
		case 5:
			wentiGuli.setText(this.getResources().getIdentifier(
					"com.tiger.life:string/eredar_q_desc_5",
					null, null));
			break;
		case 10:
			wentiGuli.setText(this.getResources().getIdentifier(
					"com.tiger.life:string/eredar_q_desc_10",
					null, null));
			break;
		case 15:
			wentiGuli.setText(this.getResources().getIdentifier(
					"com.tiger.life:string/eredar_q_desc_15",
					null, null));
			break;
		case 20:
			wentiGuli.setText(this.getResources().getIdentifier(
					"com.tiger.life:string/eredar_q_desc_20",
					null, null));
			break;
		case 25:
			wentiGuli.setText(this.getResources().getIdentifier(
					"com.tiger.life:string/eredar_q_desc_25",
					null, null));
			break;
		case 30:
			wentiGuli.setText(this.getResources().getIdentifier(
					"com.tiger.life:string/eredar_q_desc_30",
					null, null));
			break;
		default:
			wentiGuli.setText("");
			break;
		}
	}

	private boolean validThreeChecked() {
		if (subject_1.isChecked() || subject_2.isChecked()
				|| subject_3.isChecked()) {
			return true;
		} else {
			return false;
		}
	}

	private boolean validFourChecked() {
		if (bb_subject_1.isChecked() || bb_subject_2.isChecked()
				|| bb_subject_3.isChecked() || bb_subject_4.isChecked()) {
			return true;
		} else {
			return false;
		}
	}

	class ApkHolder {
		CheckBox millSelect;
		TextView typeName;
		String key;
		String rieNum;
	}

	private class CalorieAdapter extends BaseAdapter {

		private LayoutInflater mInflater;

		public CalorieAdapter(Context context) {
			this.mInflater = LayoutInflater.from(context);
		}

		public int getCount() {
			// TODO Auto-generated method stub
			if (datas == null)
				return 0;
			return datas.size();
		}

		public Object getItem(int arg0) {
			// TODO Auto-generated method stub
			if (datas == null)
				return null;
			return datas.get(arg0);
		}

		public long getItemId(int arg0) {
			// TODO Auto-generated method stub
			return arg0;
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			ApkHolder holder = null;
			if (convertView == null) {
				holder = new ApkHolder();
				convertView = mInflater.inflate(R.layout.typeitem, null);
				holder.millSelect = (CheckBox) convertView
						.findViewById(R.id.shiwuselect);
				holder.typeName = (TextView) convertView
						.findViewById(R.id.shiwuname);

			} else {
				holder = (ApkHolder) convertView.getTag();
			}

			holder.typeName.setText(datas.get(position)[1]);
			holder.key = datas.get(position)[0];
			holder.rieNum = datas.get(position)[2];
			holder.millSelect.setChecked(false);
			
			convertView.setTag(holder);
			return convertView;
		}
	}
	private void showShiwuDialog(int position){
		if(datas!=null)
			datas.clear();
		switch(position){
		case 0:
			datas=CommonUtil.getListData(this, R.array.zhushi);
			break;
		case 1:
			datas=CommonUtil.getListData(this, R.array.yinpin);
			break;
		case 2:
			datas=CommonUtil.getListData(this, R.array.shuiguo);
			break;
		case 3:
			datas=CommonUtil.getListData(this, R.array.shucai);
			break;
		case 4:
			datas=CommonUtil.getListData(this, R.array.roudan);
			break;
		case 5:
			datas=CommonUtil.getListData(this, R.array.lingshi);
			break;
		case 6:
			datas=CommonUtil.getListData(this, R.array.dianxin);
			break;
		case 7:
			datas=CommonUtil.getListData(this, R.array.MCkuaican);
			break;
		case 8:
			datas=CommonUtil.getListData(this, R.array.KFCkuaican);
			break;
		}
		caAdapter.notifyDataSetChanged();
		if(shiwuDialog==null){
		shiwuDialog=new AlertDialog.Builder(CheckActivity.this)
		.setTitle("请选择食物").setView(dataView)
		.setNegativeButton("确定", new DialogInterface.OnClickListener(){

			@Override
			public void onClick(DialogInterface dialog, int which) {
				dialog.dismiss();
				// TODO Auto-generated method stub
				String shiwutxt="";
				for(int i=0;i<selectedNames.size();i++){
					shiwutxt+=selectedNames.get(i);
					if(i<selectedNames.size()-1){
						shiwutxt+="+";
					}
				}
				checkedShiwu.setText(shiwutxt);
			}
			
		}).show();
		}else{
			shiwuDialog.show();
		}
	}
	AlertDialog shiwuDialog=null;
}